import ACCESSENUM from "./accessEnum";

interface userType {
  userName: string;
  userRole?: string;
}
const checkAccess = (
  loginUser: userType,
  needAccess = ACCESSENUM.NOT_LOGIN
) => {
  const loginUserAccess = loginUser?.userRole ?? ACCESSENUM.NOT_LOGIN;
  console.log(`output->loginUserAccess`, loginUserAccess);
  if (needAccess === ACCESSENUM.NOT_LOGIN) {
    return true;
  }

  if (needAccess === ACCESSENUM.USER) {
    if (loginUserAccess === ACCESSENUM.NOT_LOGIN) {
      return false;
    }
  }

  if (needAccess === ACCESSENUM.Admin) {
    if (loginUserAccess !== ACCESSENUM.Admin) {
      return false;
    }
  }
  return true;
};

export default checkAccess;
